package cn.kgc.springcloud.controller;

import cn.kgc.springcloud.clients.CnsulClient;
import cn.kgc.springcloud.entity.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * @author 课工场
 * @date 2025/1/10
 * @description
 */
@RestController
@RequestMapping("feign")
public class FeignController {

    @Resource
    private CnsulClient cnsulClient;

    @GetMapping("m1")
    public String   method1(){
        //  请求  http://locahost:8510/consul/m1  restTemplate   openfeign
        String result = cnsulClient.method1();
        return "FeignController method1 ok  => consul =>"+result;
    }


    //  /feign/m2?id=10
    @GetMapping("m2")
    public String   method2(Integer id){
        System.out.println(" feiController id = " + id);
        String result = cnsulClient.method2(id);
        return "FeignController method1 ok  => consul =>"+result;
    }

    @GetMapping("m3")
    public String   method3(Integer id,String info){
        System.out.println(" feiController id = " + id);
        String result = cnsulClient.method3(id,info);
        return "FeignController method1 ok  => consul =>"+result;
    }


    @GetMapping("m4/{id}")
    public String   method4(@PathVariable("id") Integer id){
        System.out.println(" feiController id = " + id);
        String result = cnsulClient.method4(id);
        return "FeignController method1 ok  => consul =>"+result;
    }

    @GetMapping("m5")
    public String   method5(){

        User user = new User();
        user.setId(1);
        user.setUsername("xiaoming");
        user.setPassword("123456");

        String result = cnsulClient.method5(user.getId(),user.getUsername(),user.getPassword());
        return "FeignController method1 ok  => consul =>"+result;
    }

    @GetMapping("m6")
    public String   method6(){

        User user = new User();
        user.setId(1);
        user.setUsername("xiaoming");
        user.setPassword("123456");

        String result = cnsulClient.method6(user);
        return "FeignController method1 ok  => consul =>"+result;
    }


    @GetMapping("m7")
    public String   method7(){

        Integer[] ids = {1,2,3,4,5};
        String result = cnsulClient.method7(ids);
        return "FeignController method1 ok  => consul =>"+result;
    }

    @GetMapping("m8")
    public User   method8(){

        //  openfeign实现参数接收时 会进行自动数据类型转换
        User user = cnsulClient.method8();
        return  user;

    }

    @GetMapping("m9")
    public List<User>  method9(){
        List<User> users = cnsulClient.method9();
        return  users;
    }


    @GetMapping("m10")
    public HashMap<String,Object> method10(){
        HashMap<String, Object> result = cnsulClient.method10();
        return  result;
    }
}
